<template>
    <div class="weatherWrap">
        <div class="icon">
            <!-- 天气图标 -->
            <div>
                <ZSIcon :symbol="true" icon="icon-richu" :styles="{ width: '24px', height: '24px' }"
                    v-if="title.includes('晴')"></ZSIcon>
                <ZSIcon :symbol="true" icon="icon-weibiaoti" :styles="{ width: '24px', height: '24px' }"
                    v-else-if="title.includes('多云')"></ZSIcon>
                <ZSIcon :symbol="true" icon="icon-xiayu" :styles="{ width: '24px', height: '24px' }" v-else></ZSIcon>
            </div>
        </div>
        <div class="right">
            <div class="title">{{ title }}</div>
            <div class="celsius">{{ celsius }}</div>
        </div>
    </div>
</template>
<script>
import ZSIcon from '@/components/ZSIcon/ZSIcon.vue';
export default {
    name: 'ZSWeather',
    components: { ZSIcon },
    data() {
        return {
            setInt: null,
            // 摄氏度
            celsius: '',
            // 
            title: '',
        }
    },
    methods: {
        getweather() {
            this.getAxios(this.$getweather, {}).then((res) => {
                if (res.code == 200) {
                    let gw = res.data.GW.split(' ');
                    let dw = res.data.DW.split(' ');
                    let celsius = gw[1] + '~' + dw[1];
                    let title = res.data.TQ;
                    this.celsius = celsius;
                    this.title = title;
                }
            });
        },
        start() {
            this.end();
            this.getweather();
            // 0.5h请求一次
            setInterval(() => {
                this.getweather();
            }, 1800000)

        },
        end() {
            clearInterval(this.setInt);
            this.setInt = null;
        },
    },
    destroyed() {
        this.end();
    },
    mounted() {
        this.start();
    },
}
</script>
<style lang="less" scoped>
.weatherWrap {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;

    .icon {}

    .right {
        display: flex;
        flex-direction: column;
        align-items: center;
        margin-left: 12px;

        .title {
            font-family: AlibabaPuHuiTi;
            font-size: 16px;
            color: #7C909E;
        }

        .celsius {
            font-family: PangMenZhengDao;
            font-size: 18px;
            font-weight: 400;
            color: #C0D1DE;
        }
    }
}
</style>